package com.itheima.cases;

import java.util.Scanner;

public class TextDemo4 {
    public static void main(String[] args) {
        Scanner rs = new Scanner(System.in);
        System.out.println("请输入四位整数:");
        int insert = rs.nextInt();
        System.out.println("加密后的结果是：" + encrypt(insert));
    }

    public static String encrypt(int Number) {
        //Number = 1983
        int[] Numbers = split(Number);
        for (int i = 0; i < Numbers.length; i++) {
            Numbers[i] = (Numbers[i] + 5) % 10;
        }
        reverse(Numbers);
        String data = "";
        for (int i = 0; i < Numbers.length; i++) {
            data += Numbers[i];
        }
        return data;
    }

    public static void reverse(int[] Numbers) {
        for (int i = 0, j = Numbers.length - 1; i < j; i++, j--) {
            int temp = Numbers[j];
            Numbers[j] = Numbers[i];
            Numbers[i] = temp;
        }
    }

    public static int[] split(int Number) {
        int[] Numbers = new int[4];
        Numbers[0] = Number / 1000;
        Numbers[1] = (Number / 100) % 10;
        Numbers[2] = (Number / 10) % 10;
        Numbers[3] = Number % 10;
        return Numbers;
    }
}
